<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>${run['experiment']['name']}</title>
</head>
<body>

<%
from datetime import datetime
import dateutil.parser

import matplotlib.pyplot as plt

import seaborn as sns

def plot(obj, t):
    fig, ax = plt.subplots(figsize=(4, 3))
    ax.plot(obj)
    fig.savefig(t + '.png', bbox_inches='tight', pad_inches=0)
    return '<img src="{}.png" width="300px"></img>'.format(t)
%>


<%def name="cfg(obj)">
    % if isinstance(obj, dict):
        <ul>
        % for k, v in sorted(obj.items()):
            <li><b>${k}</b>${cfg(v)}</li>
        % endfor
        </ul>
    % else:
        = ${obj}
    % endif
</%def>


<%def name="nfo(obj, t)">
    % if isinstance(obj, dict):
        <ul>
        % for k, v in sorted(obj.items()):
            <li><b>${k}</b>${nfo(v, t + '.' + k)}</li>
        % endfor
        </ul>
    % elif isinstance(obj, list):
        ${plot(obj, t)}
    % else:
        = ${obj}
    % endif
</%def>



<h1>${run['experiment']['name']}</h1>
<table>
    <tr><td>Status</td><td>${run['status'] }</td></tr>
    <tr><td>Result</td><td>${run.get('result') }</td></tr>
    <tr><td>Elapsed Time</td><td>${(dateutil.parser.parse(run['stop_time']) - dateutil.parser.parse(run['start_time'])).total_seconds() / 60 } minutes</td></tr>
    <tr><td>Start Time</td><td>${run['start_time']}</td></tr>
    <tr><td>Stop Time</td><td>${run['stop_time']}</td></tr>
    <tr><td>Heartbeat</td><td>${run['heartbeat']}</td></tr>
</table>

<h2>Config</h2>
${cfg(config)}

<h2>Info</h2>
${nfo(info, 'info')}

</body>
</html>
